#include "stdafx.h"
#include "PlayerSlave.h"
PlayerSlave::PlayerSlave(PlayerId stPlayerId)
	:PlayerHome(stPlayerId)
{
	m_nTimerSendSlaves = 0;
	LOGGER_INFO("PlayerSlave:%p,",this);
}
PlayerSlave::~PlayerSlave()
{
	LOGGER_INFO("~PlayerSlave:%p,",this);
	for (UInt32 i = 0; i < m_arSlaves.size(); i++)
	{
		singleton<SlaveManager>::instance().Remove(m_arSlaves[i]);
	}
	DestroyTimer(m_nTimerSendSlaves);
}

void PlayerSlave::OnTimerSendSlaves(UInt32 nTimerId)
{
	if(m_nTimerSendSlaves != nTimerId)
	{
		LOGGER_ERROR("OnTimerSendSlaves,m_nTimerSendSlaves:%d,nTimerId:%d",m_nTimerSendSlaves,nTimerId);
		DestroyTimer(nTimerId);
	}	
	DestroyTimer(m_nTimerSendSlaves);
	sendSlaves();
}

bool PlayerSlave::addSlave(Int32 char_id)
{
	if (m_arSlaves.size() >= MAX_SLAVES_SIZE)
	{
		LOGGER_ERROR("addSlave,m_arSlaves.size() >= CharInfo::MAX_SLAVES_SIZE");
		return false;
	}
	Int32 nInnerId = generatePetInnerId();
	if (nInnerId == 0)
		return false;
	Player* pPlayer = singleton<PlayerManager>::instance().GetByCharId(char_id);
	if (pPlayer == NULL)
	{
		return false;
	}
	pPlayer->encode();
	if (!hasFriend(char_id))
	{
		addFriend(char_id);
	}
	FriendInfo* pFriendInfo = getFriendInfo(char_id);
	if (pFriendInfo == NULL)
	{
		return false;
	}

	SlaveInfo info;
	info.m_nCharId = pPlayer->m_nCharId;
	info.m_szCharName[MAX_CHAR_NAME_SIZE-1] = '\0';
	pPlayer->m_stCharInfo.m_szCharName[MAX_CHAR_NAME_SIZE-1] = '\0';
	strcpy(info.m_szCharName,pPlayer->m_stCharInfo.m_szCharName);
	info.m_nRace = pPlayer->m_nRace;
	info.m_nGender = pPlayer->m_nGender;
	info.m_nLevel = pPlayer->m_nLevel;
	info.m_nHP = pPlayer->m_stCharInfo.m_nHP + pPlayer->m_stCharInfo.m_nHPAdd;
	info.m_nAP = pPlayer->m_stCharInfo.m_nAP + pPlayer->m_stCharInfo.m_nAPAdd;
	info.m_nDP = pPlayer->m_stCharInfo.m_nDP + pPlayer->m_stCharInfo.m_nDPAdd;
	info.m_nSP = pPlayer->m_stCharInfo.m_nSP + pPlayer->m_stCharInfo.m_nSPAdd;

	info.m_nResistHL = pPlayer->m_stCharInfo.m_nResistHL + pPlayer->m_stCharInfo.m_nResistHLAdd;
	info.m_nResistBD = pPlayer->m_stCharInfo.m_nResistBD + pPlayer->m_stCharInfo.m_nResistBDAdd;
	info.m_nResistHS = pPlayer->m_stCharInfo.m_nResistHS + pPlayer->m_stCharInfo.m_nResistHSAdd;

	info.m_nPropBJ = pPlayer->m_stCharInfo.m_nPropBJ + pPlayer->m_stCharInfo.m_nPropBJAdd;
	info.m_nPropSB = pPlayer->m_stCharInfo.m_nPropSB + pPlayer->m_stCharInfo.m_nPropSBAdd;
	info.m_nPropFJ = pPlayer->m_stCharInfo.m_nPropFJ + pPlayer->m_stCharInfo.m_nPropFJAdd;
	info.m_nPropLJ = pPlayer->m_stCharInfo.m_nPropLJ + pPlayer->m_stCharInfo.m_nPropLJAdd;

	info.m_nSkillsSize = pPlayer->m_stCharInfo.m_nSkillsSize;
	for (Int32 i = 0; i < MAX_SKILLS_SIZE; i++)
		info.m_arSkills[i] = pPlayer->m_stCharInfo.m_arSkills[i];
	for (Int32 i = 0; i < DEFAULT_SKILL_SIZE; i++)
		info.m_arDefaultSkills[i] = pPlayer->m_stCharInfo.m_arDefaultSkills[i];
	info.m_nBattleMode = pPlayer->m_stCharInfo.m_nBattleMode;
	for (Int32 i = 0; i < MAX_AUTO_BATTLE_SKILLS_SIZE; i++)
	{
		info.m_arAutoBattleSkills[i] = pPlayer->m_stCharInfo.m_arAutoBattleSkills[i];
		info.m_arAutoBattleSkillsSoul[i] = pPlayer->m_stCharInfo.m_arAutoBattleSkillsSoul[i];
	}
	for (Int32 i = 0; i < MAX_ITEM_EQUIP_SIZE; i++)
		info.m_arEquipImageId[i] = pPlayer->m_stCharInfo.m_arEquipImageId[i];
	info.m_nInnerId = nInnerId;
	Slave *pSlave = singleton<SlaveManager>::instance().CreateFromSlaveInfo(info);
	if (pSlave == NULL)
	{
		LOGGER_ERROR("addSlave,pSlave == NULL,char_id:%d",char_id);
		return false;
	}
	pSlave->SetOwnerPlayer((Player*)this);
	pSlave->decodeSkills();

	if(pPlayer->m_stCharInfo.m_stSlaveMaster.m_nCharId != 0)
	{
		Player::removeSlaveData(pPlayer->m_stCharInfo.m_stSlaveMaster.m_nCharId,char_id);
	}

	SimpleCharInfo slaveMaster;

	slaveMaster.m_nCharId = m_nCharId;
	slaveMaster.m_szCharName[MAX_CHAR_NAME_SIZE - 1] = '\0';
	if (!m_strCharName.empty())
		strcpy(slaveMaster.m_szCharName,m_strCharName.c_str());
	slaveMaster.m_nRace = m_nRace;
	slaveMaster.m_nGender = m_nGender;
	slaveMaster.m_nLevel = m_nLevel;
	slaveMaster.m_nValue = m_nValue;

	Player::updateSlaveMaster(pPlayer->m_nCharId,slaveMaster);

	m_arSlaves.push_back(pSlave->GetSlaveId());
	PrepareSendSlaves();
	PrepareSyncCharInfo();
	pPlayer->PrepareSendSlaves();
	return true;
}
bool PlayerSlave::addSlave(SoulCharInfo& soulInfo)
{
	if (m_arSlaves.size() >= MAX_SLAVES_SIZE)
	{
		LOGGER_ERROR("addSlave,m_arSlaves.size() >= CharInfo::MAX_SLAVES_SIZE");
		return false;
	}
	Int32 nInnerId = generatePetInnerId();
	if (nInnerId == 0)
		return false;
	/*pPlayer->encode();*/
	if (!hasFriend(soulInfo.m_nCharId))
		addFriend(soulInfo.m_nCharId,soulInfo.m_szCharName,soulInfo.m_nLevel,soulInfo.m_nRace,soulInfo.m_nGender,soulInfo.m_nValue);
	
	FriendInfo* pFriendInfo = getFriendInfo(soulInfo.m_nCharId);
	if (pFriendInfo == NULL)
	{
		return false;
	}

	SlaveInfo info;
	info.m_nCharId = soulInfo.m_nCharId;
	info.m_szCharName[MAX_CHAR_NAME_SIZE-1] = '\0';
	soulInfo.m_szCharName[MAX_CHAR_NAME_SIZE-1] = '\0';
	strcpy(info.m_szCharName,soulInfo.m_szCharName);
	info.m_nRace = soulInfo.m_nRace;
	info.m_nGender = soulInfo.m_nGender;
	info.m_nLevel = soulInfo.m_nLevel;
	info.m_nHP = soulInfo.m_nHP;
	info.m_nAP = soulInfo.m_nAP;
	info.m_nDP = soulInfo.m_nDP;
	info.m_nSP = soulInfo.m_nSP;

	info.m_nResistHL = soulInfo.m_nResistHL;
	info.m_nResistBD = soulInfo.m_nResistBD;
	info.m_nResistHS = soulInfo.m_nResistHS;

	info.m_nPropBJ = soulInfo.m_nPropBJ;
	info.m_nPropSB = soulInfo.m_nPropSB;
	info.m_nPropFJ = soulInfo.m_nPropFJ;
	info.m_nPropLJ = soulInfo.m_nPropLJ;

	info.m_nSkillsSize = soulInfo.m_nSkillsSize;
	for (Int32 i = 0; i < MAX_SKILLS_SIZE; i++)
		info.m_arSkills[i] = soulInfo.m_arSkills[i];
	for (Int32 i = 0; i < DEFAULT_SKILL_SIZE; i++)
		info.m_arDefaultSkills[i] = soulInfo.m_arDefaultSkills[i];
	info.m_nBattleMode = soulInfo.m_nBattleMode;
	for (Int32 i = 0; i < MAX_AUTO_BATTLE_SKILLS_SIZE; i++)
	{
		info.m_arAutoBattleSkills[i] = soulInfo.m_arAutoBattleSkills[i];
		info.m_arAutoBattleSkillsSoul[i] = soulInfo.m_arAutoBattleSkills[i];
	}
	for (Int32 i = 0; i < MAX_ITEM_EQUIP_SIZE; i++)
		info.m_arEquipImageId[i] = soulInfo.m_arEquipImageId[i];
	info.m_nInnerId = nInnerId;
	Slave *pSlave = singleton<SlaveManager>::instance().CreateFromSlaveInfo(info);
	if (pSlave == NULL)
	{
		LOGGER_ERROR("addSlave,pSlave == NULL,soulInfo.m_nCharId:%d",soulInfo.m_nCharId);
		return false;
	}
	pSlave->SetOwnerPlayer((Player*)this);
	pSlave->decodeSkills();

	SimpleCharInfo slaveMaster;

	slaveMaster.m_nCharId = m_nCharId;
	slaveMaster.m_szCharName[MAX_CHAR_NAME_SIZE - 1] = '\0';
	if (!m_strCharName.empty())
		strcpy(slaveMaster.m_szCharName,m_strCharName.c_str());
	slaveMaster.m_nRace = m_nRace;
	slaveMaster.m_nGender = m_nGender;
	slaveMaster.m_nLevel = m_nLevel;
	slaveMaster.m_nValue = m_nValue;

	Player::updateSlaveMaster(soulInfo.m_nCharId,slaveMaster);

	m_arSlaves.push_back(pSlave->GetSlaveId());
	PrepareSendSlaves();
	PrepareSyncCharInfo();
	//pPlayer->PrepareSendSlaves();
	return true;
}
bool PlayerSlave::hasSlave(Int32 char_id)
{
	for (UInt32 i = 0; i < m_arSlaves.size(); i++)
	{
		Slave *pSlave = singleton<SlaveManager>::instance().Get(m_arSlaves[i]);
		if (pSlave != NULL)
		{
			if(pSlave->GetSlaveInfo().m_nCharId == char_id)
				return true;
		}
	}
	return false;
}

Slave* PlayerSlave::getSlaveByIndex(Int32 nIndex)
{
	if (nIndex < 0 || nIndex >= (Int32)m_arSlaves.size())
	{
		LOGGER_ERROR("getSlaveByIndex,nIndex < 0 || nIndex >= m_arSlaves.size()");
		return NULL;
	}
	return singleton<SlaveManager>::instance().Get(m_arSlaves[nIndex]);
}
Slave* PlayerSlave::getSlaveByCharId(Int32 nCharId)
{
	for (UInt32 i = 0; i < m_arSlaves.size(); i++)
	{
		Slave *pSlave = singleton<SlaveManager>::instance().Get(m_arSlaves[i]);
		if (pSlave != NULL)
		{
			if (pSlave->GetSlaveInfo().m_nCharId == nCharId)
				return pSlave;
		}
	}
	return NULL;
}
Slave* PlayerSlave::getSlaveByInnerId(Int32 nInnerId)
{
	for (UInt32 i = 0; i < m_arSlaves.size(); i++)
	{
		Slave *pSlave = singleton<SlaveManager>::instance().Get(m_arSlaves[i]);
		if (pSlave != NULL)
		{
			if (pSlave->GetSlaveInfo().m_nInnerId == nInnerId)
				return pSlave;
		}
	}
	return NULL;
}

SlaveInfo* PlayerSlave::getSlaveInfoByInnerId(CharInfo& stCharInfo,Int32 nInnerId)
{
	if(stCharInfo.m_nSlavesSize > MAX_PETS_SIZE)
		return NULL;
	for (UInt32 i = 0; i < stCharInfo.m_nSlavesSize; i++)
	{
		if(stCharInfo.m_arSlaves[i].m_nInnerId == nInnerId)
			return &(stCharInfo.m_arSlaves[i]);
	}
	return NULL;
}
void PlayerSlave::removeSlave(Int32 nCharId)
{
	Int32 nIndex = 0;
	std::vector<SlaveId>::iterator iter = m_arSlaves.begin();
	std::vector<SlaveId>::iterator iterend = m_arSlaves.end();
	for (; iter != iterend; iter++)
	{
		Slave* pSlave = singleton<SlaveManager>::instance().Get((*iter));
		if (pSlave != NULL && pSlave->GetSlaveInfo().m_nCharId == nCharId)
		{
			Player::updateSlaveMaster(pSlave->GetSlaveInfo().m_nCharId,SimpleCharInfo());

			if(nIndex == m_stCharInfo.m_nSlaveJoinBattleIndex)
			{
				if (m_stCharInfo.m_nPartnerType == PARTNER_TYPE_SLAVE)
					sendPartnerWatch(false);
				setSlaveJoinBattleIndex(-1);
			}

			singleton<SlaveManager>::instance().Remove((*iter));

			m_arSlaves.erase(iter);
			break;
		}
		nIndex++;
	}

	PrepareSyncCharInfo();
}
Slave* PlayerSlave::getSlaveBySlaveId(Int32 nSlaveId)
{	Int32 nIndex = 0;
	std::vector<SlaveId>::iterator iter = m_arSlaves.begin();
	std::vector<SlaveId>::iterator iterend = m_arSlaves.end();
	for (; iter != iterend; iter++)
	{
		if ((*iter) == nSlaveId)
		{
			return singleton<SlaveManager>::instance().Get((*iter));
		}
	}
	return NULL;
}
void PlayerSlave::removeSlaveBySlaveId(SlaveId id)
{
	Int32 nIndex = 0;
	std::vector<SlaveId>::iterator iter = m_arSlaves.begin();
	std::vector<SlaveId>::iterator iterend = m_arSlaves.end();
	for (; iter != iterend; iter++)
	{
		if ((*iter) == id)
		{
			Slave* pSlave = singleton<SlaveManager>::instance().Get((*iter));
			if (pSlave != NULL)
				Player::updateSlaveMaster(pSlave->GetSlaveInfo().m_nCharId,SimpleCharInfo());

			if(nIndex == m_stCharInfo.m_nSlaveJoinBattleIndex)
			{
				if (m_stCharInfo.m_nPartnerType == PARTNER_TYPE_SLAVE)
					sendPartnerWatch(false);
				setSlaveJoinBattleIndex(-1);
			}
			singleton<SlaveManager>::instance().Remove(id);
			
			m_arSlaves.erase(iter);
			break;
		}
		nIndex++;
	}

	PrepareSyncCharInfo();
}
void PlayerSlave::decodeSlaves()
{
	if (m_stCharInfo.m_nSlavesSize > MAX_SLAVES_SIZE)
	{
		LOGGER_ERROR("decodeSlaves,m_stCharInfo.m_nSlavesSize > CharInfo::MAX_SLAVES_SIZE");
		return;
	}
	m_arSlaves.clear();
	Slave *pSlave = NULL;
	for (UInt32 i = 0; i < m_stCharInfo.m_nSlavesSize; i++)
	{
		if (m_stCharInfo.m_arSlaves[i].m_nCharId != 0 )
		{
			m_stCharInfo.m_arSlaves[i].m_szCharName[MAX_CHAR_NAME_SIZE-1] = '\0';
			pSlave = singleton<SlaveManager>::instance().CreateFromSlaveInfo(m_stCharInfo.m_arSlaves[i]);
			if (pSlave == NULL)
			{
				LOGGER_ERROR("decodeSlaves,m_stCharInfo.m_arSlaves[i].m_nCharId != 0,but pSlave == NULL,m_nCharId:%d",m_stCharInfo.m_arSlaves[i].m_nCharId);
			}
			else
			{
				pSlave->SetOwnerPlayer((Player*)this);
				//pSlave->updateMaxValue();
				pSlave->decodeSkills();
				m_arSlaves.push_back(pSlave->GetSlaveId());
			}
		}
	}
	if(m_stCharInfo.m_nSlaveJoinBattleIndex < 0 || m_stCharInfo.m_nSlaveJoinBattleIndex >= (Int32)m_arSlaves.size())
		m_stCharInfo.m_nSlaveJoinBattleIndex = -1;
}
void PlayerSlave::encodeSlaves()
{
	if (m_arSlaves.size() > MAX_SLAVES_SIZE)
	{
		LOGGER_ERROR("encodeSlaves,m_arSlaves.size() > CharInfo::MAX_SLAVES_SIZE");
		return;
	}

	m_stCharInfo.m_nSlavesSize = m_arSlaves.size();
	for (UInt32 i = 0; i < m_arSlaves.size(); i++)
	{
		Slave *pSlave = singleton<SlaveManager>::instance().Get(m_arSlaves[i]);
		if (pSlave != NULL)
		{
			pSlave->encodeSkills();
			m_stCharInfo.m_arSlaves[i] = pSlave->GetSlaveInfo();
		}
	}
}
void PlayerSlave::sendSlaves()
{
	if(m_stCharInfo.m_nSlaveJoinBattleIndex < 0 || m_stCharInfo.m_nSlaveJoinBattleIndex >= (Int32)m_arSlaves.size())
		m_stCharInfo.m_nSlaveJoinBattleIndex = -1;
	Slave* pSlave = getSlaveByIndex(m_stCharInfo.m_nSlaveJoinBattleIndex);
	if (pSlave != NULL)
	{
		pSlave->SetWatch(true);
	}

	PacketEncoder encoder;
	encoder.AddItem(Int32(0));
	encoder.AddItem(Int32(1500));

	encoder.AddItem(m_stCharInfo.m_stSlaveMaster.m_nCharId);
	m_stCharInfo.m_stSlaveMaster.m_szCharName[MAX_CHAR_NAME_SIZE - 1] = '\0';
	encoder.AddItem(m_stCharInfo.m_stSlaveMaster.m_szCharName);
	encoder.AddItem(m_stCharInfo.m_stSlaveMaster.m_nRace);
	encoder.AddItem(m_stCharInfo.m_stSlaveMaster.m_nGender);
	encoder.AddItem(m_stCharInfo.m_stSlaveMaster.m_nLevel);

	encoder.AddItem(Int32(m_arSlaves.size()));
	encoder.AddItem(Int32(m_stCharInfo.m_nSlaveJoinBattleIndex));
	for (UInt32 i = 0; i < m_arSlaves.size(); i++)
	{
		pSlave = singleton<SlaveManager>::instance().Get(m_arSlaves[i]);
		if (pSlave != NULL)
		{
			SlaveInfo& info = pSlave->GetSlaveInfo();
			encoder.AddItem(pSlave->GetSlaveId());
			encoder.AddItem(info.m_nInnerId);
			encoder.AddItem(info.m_nCharId);
			info.m_szCharName[MAX_CHAR_NAME_SIZE-1] = '\0';
			encoder.AddItem(info.m_szCharName);
			encoder.AddItem(info.m_nRace);
			encoder.AddItem(info.m_nGender);
			encoder.AddItem(info.m_nLevel);
			encoder.AddItem(info.m_nHP);
			encoder.AddItem(info.m_nAP);
			encoder.AddItem(info.m_nDP);
			encoder.AddItem(info.m_nSP);

			encoder.AddItem(info.m_nResistHL);
			encoder.AddItem(info.m_nResistBD);
			encoder.AddItem(info.m_nResistHS);

			encoder.AddItem(info.m_nPropBJ);
			encoder.AddItem(info.m_nPropSB);
			encoder.AddItem(info.m_nPropFJ);
			encoder.AddItem(info.m_nPropLJ);

			encoder.AddItem(Int32(MAX_ITEM_EQUIP_SIZE));
			for (Int32 j = 0; j < MAX_ITEM_EQUIP_SIZE; j++)
			{
				encoder.AddItem(Int32(info.m_arEquipImageId[j]));
			}

			if(info.m_nSkillsSize > MAX_SKILLS_SIZE)
				info.m_nSkillsSize = 0;
			encoder.AddItem(info.m_nSkillsSize);
			for (UInt32 j = 0; j < info.m_nSkillsSize; j++)
			{
				encoder.AddItem(info.m_arSkills[j].csv_id);
				encoder.AddItem(info.m_arSkills[j].level);
			}

			encoder.AddItem(Int32(info.m_nBattleMode));
			for (Int32 i = 0; i < MAX_AUTO_BATTLE_SKILLS_SIZE; i++)
			{
				encoder.AddItem(Int32(info.m_arAutoBattleSkills[i]));
			}
			for (Int32 i = 0; i < MAX_AUTO_BATTLE_SKILLS_SIZE; i++)
			{
				encoder.AddItem(Int32(info.m_arAutoBattleSkillsSoul[i]));
			}

			for (Int32 j = 0; j < DEFAULT_SKILL_SIZE; j++)
			{
				encoder.AddItem(info.m_arDefaultSkills[j]);
			}
		}
	}

	SendPacket(m_stPlayerId.nSocketId,m_stPlayerId.nSocketIdOnGate,encoder);
}
void PlayerSlave::sendSlavesCatch()
{
	PacketEncoder encoder;
	encoder.AddItem(Int32(0));
	encoder.AddItem(Int32(1503));
	if (m_stCharInfo.m_nSlavesCatchSize < 0 || m_stCharInfo.m_nSlavesCatchSize > MAX_SLAVES_CATCH_SIZE)
		m_stCharInfo.m_nSlavesCatchSize = 0;

	if(m_stCharInfo.m_nSlavesCatchSize != MAX_SLAVES_CATCH_SIZE)
		updateSlavesCatch();
	encoder.AddItem(Int32(time(NULL)) - m_stCharInfo.m_nSlavesCatchRefreshTime);
	encoder.AddItem(Int32(m_stCharInfo.m_nSlavesCatchSize));
	for (UInt32 i = 0; i < m_stCharInfo.m_nSlavesCatchSize; i++)
	{
		SimpleCharInfo& info = m_stCharInfo.m_arSlavesCatch[i];
		encoder.AddItem(info.m_nCharId);
		info.m_szCharName[MAX_CHAR_NAME_SIZE - 1] = '\0';
		encoder.AddItem(info.m_szCharName);
		encoder.AddItem(info.m_nLevel);
		encoder.AddItem(info.m_nRace);
		encoder.AddItem(info.m_nGender);
		encoder.AddItem(info.m_nValue);
	}
	SendPacket(m_stPlayerId.nSocketId,m_stPlayerId.nSocketIdOnGate,encoder);
}
Int32 PlayerSlave::generateSlaveInnerId()
{
	if (m_arSlaves.size() >= MAX_SLAVES_SIZE)
	{
		return 0;
	}
	for (Int32 i = 1; i <= MAX_SLAVES_SIZE; i++)
	{
		if (getSlaveByInnerId(i) == NULL)
			return i;
	}
	return 0;
}
bool PlayerSlave::updateSlavesCatch()
{
	if(Int32(time(NULL)) - m_stCharInfo.m_nSlavesCatchRefreshTime < 5*60)
		return false;
	m_stCharInfo.m_nSlavesCatchSize = 0;
	singleton<PlayerManager>::instance().updateSlavesCatch(m_nCharId);
	m_stCharInfo.m_nSlavesCatchRefreshTime = Int32(time(NULL));
	return true;
}
bool PlayerSlave::hasSlaveCatch(Int32 char_id)
{
	if (m_stCharInfo.m_nSlavesCatchSize < 0 || m_stCharInfo.m_nSlavesCatchSize > MAX_SLAVES_CATCH_SIZE)
		m_stCharInfo.m_nSlavesCatchSize = 0;

	for (UInt32 i = 0; i < m_stCharInfo.m_nSlavesCatchSize; i++)
	{
		SimpleCharInfo& info = m_stCharInfo.m_arSlavesCatch[i];
		if(info.m_nCharId == char_id)
			return true;
	}
	return false;
}
bool PlayerSlave::addSlaveCatch(SimpleCharInfo& simpleCharInfo)
{
	if (m_stCharInfo.m_nSlavesCatchSize < 0 || m_stCharInfo.m_nSlavesCatchSize > MAX_SLAVES_CATCH_SIZE)
		m_stCharInfo.m_nSlavesCatchSize = 0;

	if (m_stCharInfo.m_nSlavesCatchSize >= MAX_SLAVES_CATCH_SIZE)
	{
		LOGGER_ERROR("m_stCharInfo.m_nSlavesCatchSize >= MAX_SLAVES_CATCH_SIZE");
		return false;
	}
	m_stCharInfo.m_arSlavesCatch[m_stCharInfo.m_nSlavesCatchSize] = simpleCharInfo;
	m_stCharInfo.m_nSlavesCatchSize++;
	return true;
}